package app.auto.designer.view;

/**
 * Created by hp on 2018/6/19.
 */

import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;

import app.auto.designer.permission.PermissionActivity;
import app.auto.runner.base.intf.FunCallback;

public class GestureActivity extends PermissionActivity {
    protected static final float FLIP_DISTANCE = 50;
    GestureDetector mDetector;
    FunCallback callback;

    public void setCallback(FunCallback callback) {
        this.callback = callback;
    }


    public void initGesture() {
        mDetector = new GestureDetector(this, new OnGestureListener() {

            @Override
            public boolean onSingleTapUp(MotionEvent e) {
                // TODO Auto-generated method stub
                return true;
            }

            @Override
            public void onShowPress(MotionEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                // TODO Auto-generated method stub
                return true;
            }

            @Override
            public void onLongPress(MotionEvent e) {
                // TODO Auto-generated method stub

            }

            /**
             *
             * e1 The first down motion event that started the fling. e2 The
             * move motion event that triggered the current onFling.
             */
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                if (e1.getX() - e2.getX() > FLIP_DISTANCE) {
                    Log.i("TAG", "<--- left, left, go go go");
                    return true;
                }
                if (e2.getX() - e1.getX() > FLIP_DISTANCE) {
                    Log.i("TAG", "right, right, go go go --->");  //忽然觉得这个log好智障...
                    return true;
                }
                if (e1.getY() - e2.getY() > FLIP_DISTANCE) {
                    if (callback != null) {
                        callback.simpleRun(callback.getObject());
                    }
                    Log.i("TAG", "向上滑...");
                    return true;
                }
                if (e2.getY() - e1.getY() > FLIP_DISTANCE) {
                    Log.i("TAG", "向下滑...");
                    return true;
                }

                Log.d("TAG", e2.getX() + " " + e2.getY());

                return true;
            }

            @Override
            public boolean onDown(MotionEvent e) {
                // TODO Auto-generated method stub
                return true;
            }
        });

    }

//    @Override
//    public boolean onTouchEvent(MotionEvent event) {
//
////        mDetector.onTouchEvent(event);
//        return super.onTouchEvent(event);
//    }
}